/*
 * @Author: xiaxia
 * @Description: 
 * @Date: 2024-07-08 16:40:25
 * @LastEditTime: 2024-07-09 15:37:52
 * @FilePath: \project\src\api\acl\role\index.ts
 */
import request from "@/utils/request";
import { menuData, MenuListResponse, RoleInfo, RoleListResponse } from "./type";

enum API {
  GETROLELIST_URL = '/admin/acl/role/', // 获取角色list
  ADDROLE_URL = '/admin/acl/role/save', // 增加角色
  EDITROLE_URL = '/admin/acl/role/update', // 修改角色
  DELETEROLE_URL = '/admin/acl/role/remove/',  // 删除角色
  GETMENULIST_URL = '/admin/acl/permission/toAssign/', // 获取菜单list
  ADDMENU_URL = '/admin/acl/permission/doAssignAcl',  // 分配菜单
}

// 角色列表
export const reqRoleList = (page:number, limit:number, roleName:string) => request.get<any, RoleListResponse>(API.GETROLELIST_URL+`${page}/${limit}/?roleName=${roleName}`)
// 编辑和添加角色
export const reqAddEditRole = (data:RoleInfo) => {
  if(data.id) {
    return request.put<any, any>(API.EDITROLE_URL,data)
  } else {
    return request.post<any, any>(API.ADDROLE_URL,data)
  }
}
// 删除角色
export const reqDeleteRole = (id:number) => request.delete<any, any>(API.DELETEROLE_URL+id)
// 获取菜单
export const reqMenuList = (id:number) => request.get<any, MenuListResponse>(API.GETMENULIST_URL+id)
export const reqAddMenu = (data:menuData) => request.post<any, any>(API.ADDMENU_URL, data)